<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>群！</title>
<link rel="stylesheet" type="text/css" href="im.css" />
</head>
<body>
<div id="container">
        <div class="header">
            <span style="float: left;">群聊天界面</span>
            <span id="mtime" style="float: right;"></span>
        </div>
        <ul class="content">
			
		</ul>
        <div class="footer">
            <div id="user_face_icon">
                <img src="image/t2.jpg" alt="">
            </div>
            <input id="messageText" type="text" placeholder="说点什么吧..." >
            <span id="btn" onclick="sendMsg()">发送</span>
        </div>
    </div>



<script>
    var wsUrl = 'ws://127.0.0.1:9326/';
    var ws = new WebSocket(wsUrl);
    ws.onopen = function(evt) {
        console.log(evt)
        // messageCache.push("Connection open\r\n\r\n");
    };

    // var t1 = window.setTimeout(sendContent,900);
    var t2 = window.setInterval("sendContent()", 11100); //使用字符串执行方法

    function sendContent() {
        // var message = $('#add_number').val();
        var message ="123";
        if (message === '') {
            return;
        }
        // 发送
        var data = {
            action: 'isupdate',
            group:'krk3',
            msg: message,
        };
        ws.send(JSON.stringify(data));

    }

    ws.onmessage = function(evt) {
        console.log(evt.data);
        // console.log(evt);
        if (evt.data == '"1"') {
            setTimeout(function(){location.reload();},Math.random()*5000);

        }
        // messageCache.push(getNowFormatDate() + "\r\n" + fuckXSS(evt.data.substring(0, 128)) + "\r\n\r\n");
    };

    ws.onclose = function(evt) {
        //刷新页面
        // alert('连接关闭，请手动刷新');
        $('#msg').html('连接关闭，请手动刷新');
        // location.reload();
        // messageCache.push("Connection closed\r\n");
    };
</script>
<!--<script src="./tio/tiows.js"></script>-->
<!--<script src="./name.js"></script>-->
<!--<script src="./imHandler.js"></script>-->
<!--<script src="./im.js"></script>-->
</body>
</html>